import "@/assets/main.css"

import {createApp} from "vue"
import {createPinia} from "pinia"

import App from "@/App.vue"
import {router} from "@/router/Index"
//Element Plus组件相关===========
import ElementPlus from "element-plus"
import "element-plus/dist/index.css"
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import zhCn from "element-plus/dist/locale/zh-cn.mjs"
import {useBreadcrumbStore} from "@/stores/BreadcrumbStore";
import Breadcrumb from "@/domain/po/Breadcrumb";

const app = createApp(App)
const pinia = createPinia();
//注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(ElementPlus, {locale: zhCn})
app.use(pinia)
app.use(router)

app.mount("#app")

//========================== 全局路由守卫 ==========================
const breadcrumbStore = useBreadcrumbStore()
router.beforeEach(((to, from) => {
    console.log(to)
    if (to.path == "/") {
        return "/home";
    }
    //面包屑
    breadcrumbStore.clear()
    to.matched.forEach((item) => {
        if (item.meta?.showBreadcrumb) {
            breadcrumbStore.add(new Breadcrumb(item.meta.title, item.path))
        }
    })
    return true;
}))